package com.lxl.bt.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.lxl.bt.Constant;
import com.lxl.bt.R;
import com.lxl.bt.activity.BaseActivity;
import com.lxl.bt.bean.A_Login;
import com.lxl.bt.util.ACache;
import com.lxl.bt.util.GlideUtils;
import com.lxl.bt.util.Prefs;
import com.yanzhenjie.sofia.Sofia;
import com.yzq.zxinglibrary.encode.CodeCreator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Create by lvxinlong
 * on  我的二维码
 * on  2020年12月5日14:36:01
 **/
public class MyQrActivity extends BaseActivity {


    @BindView(R.id.ivBack)
    ImageView ivBack;
    @BindView(R.id.rlBack)
    RelativeLayout rlBack;
    @BindView(R.id.txt_toolbar_title)
    TextView txtToolbarTitle;
    @BindView(R.id.ivRight)
    ImageView ivRight;
    @BindView(R.id.tvRight)
    TextView tvRight;
    @BindView(R.id.rlRight)
    RelativeLayout rlRight;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.ivHead)
    ImageView ivHead;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvZh)
    TextView tvZh;
    @BindView(R.id.ivQr)
    ImageView ivQr;
    private Context context;
    ACache aCache;
    A_Login a_login;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myqr);
        ButterKnife.bind(this);
        //状态栏全透明全屏显示页面，布局能够延伸到状态栏和导航栏下方
        Sofia.with(this)
                .invasionStatusBar()
//                .statusBarLightFont()
                .statusBarDarkFont()
                .statusBarBackgroundAlpha(0)
                .invasionNavigationBar()
                .navigationBarBackgroundAlpha(0);

        context = this;
        rlBack.setVisibility(View.VISIBLE);
        txtToolbarTitle.setText("我的二维码");
        rlRight.setVisibility(View.GONE);
        ivRight.setVisibility(View.GONE);
        tvRight.setVisibility(View.VISIBLE);
        toolbar.setBackgroundResource(R.color.color_F2F2F2);
        txtToolbarTitle.setTextColor(getResources().getColor(R.color.c63));
        ivBack.setImageResource(R.mipmap.black_back);

        aCache = ACache.get(this);
        a_login = (A_Login) aCache.getAsObject(com.lxl.bt.Constant.LOGIN);
        GlideUtils.loadRadius(ivHead, Prefs.getStringValue(Constant.CityImgUrl) + a_login.getPhoto(), 5);
        tvName.setText(a_login.getName());
        tvZh.setText(a_login.getUsername());

        /*
         * contentEtString：字符串内容
         * w：图片的宽
         * h：图片的高
         * logo：不需要logo的话直接传null
         * */

        Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        ivQr.setImageBitmap(CodeCreator.createQRCode(a_login.getUsername(), 400, 400, ((BitmapDrawable) ivHead.getDrawable()).getBitmap()));


    }


//    private void commit() {
//        if (TextUtils.isEmpty(etOldPass.getText().toString())) {
//            ToastUtil.showToast(this, "请输入旧密码");
//            return;
//        }
//        if (TextUtils.isEmpty(etNewPass.getText().toString())) {
//            ToastUtil.showToast(this, "请输入新密码");
//            return;
//        }
//        if (TextUtils.isEmpty(etNewPassAgain.getText().toString())) {
//            ToastUtil.showToast(this, "请确认新密码");
//            return;
//        }
//        if (!etNewPass.getText().toString().equals(etNewPassAgain.getText().toString())) {
//            ToastUtil.showToast(this, "请确认密码是否一致");
//            return;
//        }
//
//        JsonObject jsonObject = new JsonObject();
//        //"cardNumber": "0440000000166563",
//        //"password ": "fsefs",
//        //"newPassword1": "adsdf",
//        //"newPassword2": "adsdf"
//        jsonObject.addProperty("cardNumber", tvCardno.getText().toString());
//        jsonObject.addProperty("virtualCardNumber", Prefs.getStringValue(Constant.VirtualCardNumber));
//        jsonObject.addProperty("password", etOldPass.getText().toString());
//        jsonObject.addProperty("newPassword1", etNewPass.getText().toString());
//        jsonObject.addProperty("newPassword2", etNewPassAgain.getText().toString());
//        RetrofitUtil.getInstance().create(NetApi.class, 0)
//                .editPassword(jsonObject).enqueue(new NetCallback<Result<OnlyCode>>() {
//            @Override
//            public void onSuccess(Result<OnlyCode> result) {
//                Log.w("lxl", ">>>>" + result.isSuccess());
//                if (result.isSuccess()) {
//                    ToastUtil.showToast(LoginActivity.this, "修改成功");
//                    finish();
//                } else {
//                    ToastUtil.showToast(LoginActivity.this, result.getMsg());
//                }
//
//            }
//
//            @Override
//            public void onError(String errorStr) {
//                super.onError(errorStr);
//                Log.w("lxl", ">>>>" + errorStr);
//                ToastUtil.showToast(LoginActivity.this, errorStr);
//            }
//
//        });
//    }


    @OnClick(R.id.rlBack)
    public void onClick() {
        finish();
    }
}
